package itbour.onetouchshow.activity.web;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.webkit.JavascriptInterface;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.OneToucDialog;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.lsjr.callback.EncryBeanCallBack;
import com.lsjr.utils.HttpUtils;
import com.lsjr.utils.NetUtils;
import com.three.share.SharePlatform;
import com.three.share.ThirdShareUtils;
import com.three.share.listener.ShareListener;
import com.umeng.analytics.MobclickAgent;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.List;

import itbour.onetouchshow.App;
import itbour.onetouchshow.activity.login.LoginActivity;
import itbour.onetouchshow.activity.version1_3.MainActivityV3;
import itbour.onetouchshow.activity.video.videoplay.VideoPlayPreviewActivity;
import itbour.onetouchshow.base.BaseWebMvpActivity;
import itbour.onetouchshow.base.mvp.MVPBaseActivity;
import itbour.onetouchshow.base.mvp.MVPBaseFragment;
import itbour.onetouchshow.bean.CommonJSCallBackBean;
import itbour.onetouchshow.bean.JSCallBackBean;
import itbour.onetouchshow.bean.JcmSetNavButtonBean;
import itbour.onetouchshow.bean.JsShareBean;
import itbour.onetouchshow.bean.PayInfoBean;
import itbour.onetouchshow.bean.PhoneDevInfoBean;
import itbour.onetouchshow.bean.ToJsCallBackBean;
import itbour.onetouchshow.bean.user.UserMakeTag;
import itbour.onetouchshow.constants.AppConfig;
import itbour.onetouchshow.constants.AppConst;
import itbour.onetouchshow.fragment.challengezone.ChallengeAreaFragment;
import itbour.onetouchshow.utils.DeviceUtil;
import itbour.onetouchshow.utils.L_;
import itbour.onetouchshow.utils.T_;
import itbour.onetouchshow.utils.UIUtils;
import itbour.onetouchshow.view.ActivityUtils;
import itbour.onetouchshow.widget.JSShareDialogFragment;

/**
 * Created by Administrator on 2018/5/2.
 */

public class CommWebJsContrl {

    private static final int FAST_CLICK_DELAY_TIME = 2000;
    private final int DISMISS_DIALOG = 1;
    private final int SHOW_DIALOG = 2;
    private final String MSG_TAG = "message";
    private JSCallBackBean jsCallBackBean;
    private BaseWebMvpActivity mActivity;
    //传入如果是fragment 给跳转使用
    private MVPBaseActivity mIntentActivity;
    private MVPBaseFragment mFragment;
    private JsShareBean jsShareBean;
    ShareListener shareListener = new ShareListener() {
        @Override
        public void shareSuccess() {
            T_.showToastReal("分享成功");
            String call = "javascript:" + jsShareBean.getSuccess() + "()";

            UIUtils.runInMainThread(new Runnable() {
                @Override
                public void run() {
                    mActivity.getWebView().loadUrl(call);
                }
            });
        }

        @Override
        public void shareFailure(Exception e) {
            T_.showToastReal("分享失败" + e.getMessage());
            ToJsCallBackBean toJsCallBackBean = new ToJsCallBackBean();
            toJsCallBackBean.setErrorCode(ToJsCallBackBean.ErrorCode.NativeError);
            String returnFail = new Gson().toJson(toJsCallBackBean);
            String finalCall = "javascript:" + jsShareBean.getFail() + "(" + returnFail + ")";
            L_.e("returnFail" + returnFail);

            UIUtils.runInMainThread(new Runnable() {
                @Override
                public void run() {
                    mActivity.getWebView().loadUrl(finalCall);
                }
            });
        }

        @Override
        public void shareCancel() {
            T_.showToastReal("取消分享");
            ToJsCallBackBean toJsCallBackBean = new ToJsCallBackBean();
            toJsCallBackBean.setErrorCode(ToJsCallBackBean.ErrorCode.UserCancel);
            String returnFail = new Gson().toJson(toJsCallBackBean);
            String finalCall = "javascript:" + jsShareBean.getFail() + "(" + returnFail + ")";
            L_.e("returnFail" + returnFail);
            UIUtils.runInMainThread(new Runnable() {
                @Override
                public void run() {
                    mActivity.getWebView().loadUrl(finalCall);
                }
            });


        }
    };
    private PayPlatformListener payPlatformListener;
    //防止快速点击
    private long lastClickTime = 0L;
    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == DISMISS_DIALOG) {
                (mActivity == null ? mIntentActivity : mActivity).dismissProgressDialog();
            }
            if (msg.what == SHOW_DIALOG) {
                if (msg.getData() != null) {
                    Bundle bundle = msg.getData();
                    String msg1 = bundle.getString(MSG_TAG);
                    (mActivity == null ? mIntentActivity : mActivity).showProgressDialogWithText(msg1);
                } else {
                    (mActivity == null ? mIntentActivity : mActivity).showProgressDialogWithText("加载中...");
                }
            }
        }
    };

    public CommWebJsContrl(BaseWebMvpActivity activity) {
        this.mActivity = activity;
    }

    public CommWebJsContrl(MVPBaseActivity activity, MVPBaseFragment fragment) {
        this.mIntentActivity = activity;
        this.mFragment = fragment;
    }

    public void setPayPlatformListener(PayPlatformListener payPlatformListener) {
        this.payPlatformListener = payPlatformListener;
    }

    //设置导航栏右侧按钮_B
    @JavascriptInterface
    public void jcmSetNavButtonStyle(String result) {
        L_.e(result);
        JcmSetNavButtonBean jcmSetNavButtonBean = new Gson().fromJson(result, JcmSetNavButtonBean.class);
        String text = jcmSetNavButtonBean.getText();
        int hidden = jcmSetNavButtonBean.getHidden();
        //规则contentType= -1 为文字属性 content = 1.2.3.4.5 对应常用的图标
        //v1.7新增标题栏右侧设置图片 根据contentType进行判断
        int contentType = jcmSetNavButtonBean.getContentType();
        if (mActivity != null && mActivity instanceof CommWebActivity) {
            ((CommWebActivity) mActivity).setJcmSetNavButtonBean(jcmSetNavButtonBean);
            if (contentType == -1) {
                ((CommWebActivity) mActivity).showRightTitle(hidden, text);
            } else {
                ((CommWebActivity) mActivity).showRightImage(hidden, contentType);
            }
        }

        if (mFragment != null && mFragment instanceof MVPBaseFragment) {
            ((ChallengeAreaFragment) mFragment).setJcmSetNavButtonBean(jcmSetNavButtonBean);
            if (contentType == -1) {
                ((ChallengeAreaFragment) mFragment).showRightTitle(hidden, text);
            } else {
                ((ChallengeAreaFragment) mFragment).showRightImage(hidden, contentType);
            }
        }
    }

    //Js调原生回退多少个页面 即结束多少个页面 V1.7 新增
    @JavascriptInterface
    public void jcmJumpBackPages(String result) {
        L_.e(result);
        CommonJSCallBackBean resultBean = new Gson().fromJson(result, CommonJSCallBackBean.class);
        if (resultBean == null) return;
        int needFinishPageCount = resultBean.getPageNum();
        //遍历结束掉needFinishPageCount数量的页面
        if (needFinishPageCount > 0) {
            for (int i = 0; i < needFinishPageCount; i++) {
                Activity activity = ActivityUtils.getTopActivity();
                ActivityUtils.removeActivity(activity);
                activity.finish();
            }
            //-1回到根页面 即MainActivity
        } else if (needFinishPageCount == -1) {
            while (true) {
                if (ActivityUtils.getTopActivity() instanceof MainActivityV3) {
                    break;
                } else {
                    Activity activity = ActivityUtils.getTopActivity();
                    ActivityUtils.removeActivity(activity);
                    activity.finish();
                }
            }
        }

    }

    //开启原生新页面 v1.7 新增
    @JavascriptInterface
    public void openNewNativePage(String result) {
        if (System.currentTimeMillis() - lastClickTime < FAST_CLICK_DELAY_TIME) {
            return;
        }
        lastClickTime = System.currentTimeMillis();
        CommonJSCallBackBean resultBean = new Gson().fromJson(result, CommonJSCallBackBean.class);
        if (resultBean == null) return;
        int pageType = resultBean.getPageType();
        // 1为普通的网页 2为其它约定的页面
        switch (pageType) {
            case 1:
                if (!TextUtils.isEmpty(resultBean.getUrl()) && resultBean.getUrl().startsWith("http")) {
                    Bundle bundle = new Bundle();
                    bundle.putString(AppConst.WEBTYPE, AppConst.TYPE_WEB);
                    bundle.putString(AppConst.WEBURL, resultBean.getUrl());
                    bundle.putString(AppConst.WEB_TITLE, resultBean.getTitle());
                    //getDisplayType ==1 弹出新页面
                    Intent intent;
                    if (resultBean.getDisplayType() == 1) {
                        intent = new Intent(mActivity == null ? mIntentActivity : mActivity, CommWebActivityWithAnim.class);
                    } else {
                        intent = new Intent(mActivity == null ? mIntentActivity : mActivity, CommWebActivity.class);
                    }
                    intent.putExtras(bundle);
                    (mActivity == null ? mIntentActivity : mActivity).startActivity(intent);

                }
                break;
            case 2:
                //开启弹框视频页面
                Bundle bundle = new Bundle();
                bundle.putString(AppConst.JS_CALLBACK_URL, resultBean.getUrl());
                bundle.putBoolean(AppConst.KEY_SHOW_BOTTOM_CONTROLLER, (resultBean.getAccessory1() != null && resultBean.getAccessory1().equals("1")));
                Intent intent = new Intent(mActivity == null ? mIntentActivity : mActivity, VideoPlayPreviewActivity.class);
                intent.putExtras(bundle);
                (mActivity == null ? mIntentActivity : mActivity).startActivity(intent);
                break;
        }
    }

    //支付开通会员订单
    @JavascriptInterface
    public void jcmNativePayVip(String result) {
        //mActivity.showProgressDialogWithText("");
        handler.sendEmptyMessage(SHOW_DIALOG);
        MobclickAgent.onEvent(mActivity, "c4_pay_vip_pay_click");
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                jsCallBackBean = new Gson().fromJson(result, JSCallBackBean.class);
                if (mActivity instanceof CreateOrderActivity) {
                    ((CreateOrderActivity) mActivity).jsCallBackBean = jsCallBackBean;
                }
                handler.sendEmptyMessage(DISMISS_DIALOG);
                if (NetUtils.isConnected(UIUtils.getContext())) {
                    onOrderPay(jsCallBackBean.getOrderId() + "");
                } else {
                    T_.showCustomToast("请检查网络");
                }
            }
        });

    }

    @JavascriptInterface
    public void jcmNativePay(String result) {
        handler.sendEmptyMessage(SHOW_DIALOG);
        MobclickAgent.onEvent(mActivity, "c3_confirm_remove_wm_pay_click");
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                jsCallBackBean = new Gson().fromJson(result, JSCallBackBean.class);
                if (mActivity instanceof CreateOrderActivity) {
                    ((CreateOrderActivity) mActivity).jsCallBackBean = jsCallBackBean;
                }
                handler.sendEmptyMessage(DISMISS_DIALOG);
                if (NetUtils.isConnected(UIUtils.getContext())) {
                    onOrderPay(jsCallBackBean.getOrderId() + "");
                } else {
                    T_.showCustomToast("请检查网络");
                    // handler.sendEmptyMessage(DISMISS_DIALOG);
                }
            }
        });

    }

    /**
     * 积分去水印
     *
     * @param result
     */
    @JavascriptInterface
    public void jcmPtsRemoveWmSuccess(String result) {
        //handler.sendEmptyMessage(SHOW_DIALOG);
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                jsCallBackBean = new Gson().fromJson(result, JSCallBackBean.class);
                UserMakeTag userMakeTag = UserMakeTag.REMOVEWATER;
                EventBus.getDefault().post(userMakeTag);
                mActivity.finish();
            }
        });
    }

    @JavascriptInterface
    public void jcmNativePayRechargeXM(String result) {
        L_.e("jcmNativePayRechargeXM :" + result);
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                jsCallBackBean = new Gson().fromJson(result, JSCallBackBean.class);
                if (mActivity instanceof CommWebActivity) {
                    ((CommWebActivity) mActivity).jsCallBackBean = jsCallBackBean;
                }
                if (NetUtils.isConnected(UIUtils.getContext())) {
                    onOrderPay(jsCallBackBean.getOrderId() + "");
                } else {
                    T_.showCustomToast("请检查网络");
                    // handler.sendEmptyMessage(DISMISS_DIALOG);
                }
            }
        });
    }

    public void onOrderPay(String orderId) {
        mActivity.showProgressDialogWithText("");
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("device", AppConst.ANDROID_DEVICE);
        stringObjectHashMap.put("userId", App.getUserId());
        stringObjectHashMap.put("orderId", orderId + "");
        HttpUtils.getInstance().executeGet(AppConfig.GETORDERPAYPARAM_V1_0, stringObjectHashMap, new EncryBeanCallBack() {
            @Override
            protected void onXError(String exception) {
                mActivity.dismissProgressDialog();
                T_.showToastReal(exception);
                L_.e(exception);
            }

            @Override
            protected void onSuccess(String response) {
                mActivity.dismissProgressDialog();
                PayInfoBean payInfoBean = new Gson().fromJson(response, PayInfoBean.class);
                if (payInfoBean.getPaymentPlatform() == 10) {
                    //weiXinPay(payInfoBean);
                    //TODO
                    if (payPlatformListener != null) {
                        payPlatformListener.onPayWeiXin(payInfoBean);
                    }
                } else if (payInfoBean.getPaymentPlatform() == 20) {
                    //aliPay(payInfoBean);
                    //TODO
                    if (payPlatformListener != null) {
                        payPlatformListener.onPayZhifuBao(payInfoBean);
                    }
                }

                //L_.e(response);
            }
        });
    }

    @JavascriptInterface
    public void jcmGetDeviceInfo(String msg) {
        L_.e("jcmGetDeviceInfo" + msg);
        /**
         *  "deviceType" : "iphone x",
         "   systemVersion": "11.0.1",
         "   appVersion": "1.0.0",
         "   appName": "一键秀"
         // private String deviceType;
         // private String systemVersion;
         //  private String appVersion;
         */
        JSCallBackBean jsCallBackBean = new Gson().fromJson(msg, JSCallBackBean.class);
        String success = jsCallBackBean.getSuccess();

        String appVersionName = DeviceUtil.getAppVersionName(UIUtils.getContext());
        //手机型号
        String model = Build.MODEL;
        //系统版本
        String release = Build.VERSION.RELEASE;
        PhoneDevInfoBean phoneDevInfoBean = new PhoneDevInfoBean(model, release, appVersionName);
        String deviceInfo = new Gson().toJson(phoneDevInfoBean);
        String call = "javascript:" + success + "(" + deviceInfo + ")";
//            String call = "javascript:jcmManager.successCallbackPool[\"jcmGetDeviceInfo\"](\"{\"appVersion\":\"1.0\",\"deviceType\":\"MHA-AL00\",\"systemVersion\":\"7.0\"}\")";
        if (mActivity != null) {
            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    L_.e("call===" + call);
                    mActivity.getWebView().loadUrl(call);
                }
            });
        }
        if (mFragment != null) {
            L_.e("call===" + call);
            ((ChallengeAreaFragment) mFragment).getWebView().loadUrl(call);
        }
    }

    //调用原生弹框_1_1
    @JavascriptInterface
    public void jcmAlert(String result) {
        L_.e(result);

        JSCallBackBean jsCallBackBean = new Gson().fromJson(result, JSCallBackBean.class);
        String success = jsCallBackBean.getSuccess();
        String fail = jsCallBackBean.getFail();
        JSONObject jsonObject = JSON.parseObject(result);
        String msg = jsonObject.getString("msg");
        //String failTitle = jsonObject.getString("failTitle");
        Object failObj = jsonObject.get("failTitle");
        String successTitle = jsonObject.getString("successTitle");
        int DialogPlatformType;
        OneToucDialog.Builder builder;
        builder = new OneToucDialog.Builder(mActivity == null ? mIntentActivity : mActivity)
                .content(msg);
        if (failObj == null) {
            builder.neutralText(successTitle).
                    onNeutral(new OneToucDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(OneToucDialog dialog, DialogAction which) {
                            Log.e("TAH", "点击确定");
                            String call = "javascript:" + success + "()";
                            if (mActivity == null && mFragment != null) {
                                ((ChallengeAreaFragment) mFragment).getWebView().loadUrl(call);
                            } else {
                                mActivity.getWebView().loadUrl(call);
                            }

                        }
                    });

        } else {
            builder.positiveText(successTitle).
                    onPositive(new OneToucDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(OneToucDialog dialog, DialogAction which) {
                            Log.e("TAH", "点击确定");
                            String call = "javascript:" + success + "()";
                            if (mActivity == null && mFragment != null) {
                                ((ChallengeAreaFragment) mFragment).getWebView().loadUrl(call);
                            } else {
                                mActivity.getWebView().loadUrl(call);
                            }
                        }
                    })
                    .negativeText(failObj == null ? "" : failObj.toString()).onNegative(new OneToucDialog.SingleButtonCallback() {
                @Override
                public void onClick(OneToucDialog dialog, DialogAction which) {
                    Log.e("TAH", "点击取消");
                    ToJsCallBackBean toJsCallBackBean = new ToJsCallBackBean();
                    toJsCallBackBean.setErrorCode(ToJsCallBackBean.ErrorCode.UserCancel);
                    String call = "javascript:" + fail + "(" + new Gson().toJson(toJsCallBackBean) + ")";
                    if (mActivity == null && mFragment != null) {
                        ((ChallengeAreaFragment) mFragment).getWebView().loadUrl(call);
                    } else {
                        mActivity.getWebView().loadUrl(call);
                    }
                }
            });

        }
        builder.setType(OneToucDialog.Builder.ONE_TOUCH_TYPE)
                .cancelable(false).setmWidth(AppConst.APP_DIALOG_WIDTH)
                .show();
    }

    @JavascriptInterface
    public void jcmToast(String result) {
        L_.e(result);
        //1. 页面底部
        // 2. 页面中间
        JSCallBackBean jsCallBackBean = new Gson().fromJson(result, JSCallBackBean.class);
        String success = jsCallBackBean.getSuccess();
        JSONObject jsonObject = JSON.parseObject(result);
        String msg = jsonObject.getString("msg");
        int duration = jsonObject.getInteger("duration");
        Object positionObj = jsonObject.get("position");
        int positon = -1;
        if (positionObj != null) {
            positon = Integer.valueOf(positionObj.toString());
        }
        if (positon == 2) {
            T_.customStylesToast(msg, duration, Gravity.CENTER);
        } else {

            T_.customStylesToast(msg, duration, Gravity.BOTTOM);
        }

    }

    @JavascriptInterface
    public void jcmCallNativeShare(String result) {
        L_.e(result);
        //1. 页面底部
        // 2. 页面中间
        jsShareBean = new Gson().fromJson(result, JsShareBean.class);
        List<Integer> platforms = jsShareBean.getPlatforms();

            /*
            *
            *
                分享平台数组, 不能为空数组
                各个平台编号暂时约定如下
                微信好友          1
                微信朋友圈       2
                微信收藏          3
                新浪微博          4
                QQ空间           5
                QQ好友           6
                拷贝                7
            *
            * */
        if (platforms.size() == 1) {
            switch (platforms.get(0)) {
                /**
                 */
                case 1:
                    ThirdShareUtils.initialize().shareMedia(mActivity, SharePlatform.WX, jsShareBean.getTitle(), jsShareBean.getContent(), jsShareBean.getUrl(), jsShareBean.getThumb(), shareListener);
                    break;
                case 2:
                    ThirdShareUtils.initialize().shareMedia(mActivity, SharePlatform.WX_TIMELINE, jsShareBean.getTitle(), jsShareBean.getContent(), jsShareBean.getUrl(), jsShareBean.getThumb(), shareListener);
                    break;
                case 3:
                    break;
                case 4:
                    ThirdShareUtils.initialize().shareMedia(mActivity, SharePlatform.WEIBO, jsShareBean.getTitle(), jsShareBean.getContent(), jsShareBean.getUrl(), jsShareBean.getThumb(), shareListener);
                    break;
                case 5:
                    ThirdShareUtils.initialize().shareMedia(mActivity, SharePlatform.QQ, jsShareBean.getTitle(), jsShareBean.getContent(), jsShareBean.getUrl(), jsShareBean.getThumb(), shareListener);
                    break;
                case 6:
                    ThirdShareUtils.initialize().shareMedia(mActivity, SharePlatform.QZONE, jsShareBean.getTitle(), jsShareBean.getContent(), jsShareBean.getUrl(), jsShareBean.getThumb(), shareListener);
                    break;
                default:
                    break;
            }

        } else {
            JSShareDialogFragment jsShareDialogFragment = new JSShareDialogFragment();
            jsShareDialogFragment.setJsShareBean(jsShareBean);
            jsShareDialogFragment.setmShareListener(shareListener);
            jsShareDialogFragment.onShow(mActivity);
            //  JSShareDialogFragment.getInstance().setBuilder(jsShareBean, shareListener).onShow(mActivity);

        }

    }

    @JavascriptInterface
    public void jcmGetCurrentUserId(String result) {
        L_.e(result);
        jsCallBackBean = new Gson().fromJson(result, JSCallBackBean.class);
        String success = jsCallBackBean.getSuccess();
        JSONObject jsonObject = JSON.parseObject(result);
        int force = jsonObject.getInteger("force");
        String call = null;
        ToJsCallBackBean toJsCallBackBean = new ToJsCallBackBean();
        toJsCallBackBean.setErrorCode(ToJsCallBackBean.ErrorCode.NativeError);
        String returnFail = new Gson().toJson(toJsCallBackBean);
        L_.e("returnFail" + returnFail);
        if (force == 1 && !App.isLogin()) {
            Intent intent = new Intent(mActivity, LoginActivity.class);
            intent.putExtra(LoginActivity.FORMJS, true);
            intent.putExtra(LoginActivity.successResult, success);
            mActivity.startActivityForResult(intent, 99);
        }
        if (App.isLogin()) {
            call = "javascript:" + success + "({userId:" + App.getUserId() + "})";
        } else {
            call = "javascript:" + jsCallBackBean.getFail() + "(" + returnFail + ")";
        }
        String finalCall = call;
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mActivity.getWebView().loadUrl(finalCall);
            }
        });

    }

    @JavascriptInterface
    public void jcmCloseWindow(String result) {
        L_.e(result);
        // mAgentWeb.back();
        (mActivity == null ? mIntentActivity : mActivity).runOnUiThread(new Runnable() {
            @Override
            public void run() {
                (mActivity == null ? mIntentActivity : mActivity).onBackPressed();
            }
        });
        //finish();
    }

    @JavascriptInterface
    public void jcmLoadingShow(String result) {
        L_.e("msg" + result);
        JSONObject jsonObject = JSON.parseObject(result);
        String msg = jsonObject.getString(MSG_TAG);
        Message message = Message.obtain();
        message.what = SHOW_DIALOG;
        Bundle bundle = new Bundle();
        bundle.putString(MSG_TAG, msg);
        message.setData(bundle);
        handler.sendMessage(message);
        //handler.sendEmptyMessage(SHOW_DIALOG);
    }

    @JavascriptInterface
    public void jcmLoadingHide(String result) {
        L_.e("jcmLoadingHide");
        handler.sendEmptyMessage(DISMISS_DIALOG);
    }

    /**
     * 开启一个webview V2.3.0
     *
     * @param param
     */
    @JavascriptInterface
    public void jcmOpenWebPage(String param) {

        CommonJSCallBackBean resultBean = new Gson().fromJson(param, CommonJSCallBackBean.class);
        if (resultBean == null) return;
        Bundle bundle = new Bundle();
        bundle.putString(AppConst.WEBTYPE, AppConst.TYPE_WEB);
        bundle.putString(AppConst.WEBURL, resultBean.getUrl());
        bundle.putString(AppConst.WEB_TITLE, null);
        Intent intent;
        intent = new Intent(mActivity == null ? mIntentActivity : mActivity, AdWebActivity.class);
        intent.putExtras(bundle);
        (mActivity == null ? mIntentActivity : mActivity).startActivity(intent);
    }

    /**
     * 读取报名表单的状态
     *
     * @param result
     */
    @JavascriptInterface
    public void jcmSetBiaoDanState(String result) {
        JSONObject jsonObject = JSON.parseObject(result);
        int switchState = jsonObject.getInteger("switchState");
        if (mActivity != null && mActivity instanceof CommWebActivity) {
            ((CommWebActivity) mActivity).switchTypeFormState(switchState);
        }
    }


    public interface PayPlatformListener {
        void onPayWeiXin(PayInfoBean payInfoBean);

        void onPayZhifuBao(PayInfoBean payInfoBean);
    }


}
